package com.ruoyi.stock2.controller;

import java.util.List;

import com.ruoyi.stock2.domain.TradeDataAndForetell;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.TRADEDATA;
import com.ruoyi.stock2.service.ITRADEDATAService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交易数据Controller
 * 
 * @author ruoyi
 * @date 2019-10-21
 */
@Controller
@RequestMapping("/stock2/TRADEDATA")
public class TRADEDATAController extends BaseController
{
    private String prefix = "stock2/TRADEDATA";

    @Autowired
    private ITRADEDATAService tRADEDATAService;

    @RequiresPermissions("stock2:TRADEDATA:view")
    @GetMapping()
    public String TRADEDATA()
    {
        return prefix + "/TRADEDATA";
    }

    /**
     * 查询交易数据列表
     */
    @RequiresPermissions("stock2:TRADEDATA:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRADEDATA tRADEDATA)
    {
        startPage();
        List<TRADEDATA> list = tRADEDATAService.selectTRADEDATAList(tRADEDATA);
        return getDataTable(list);
    }


    @RequiresPermissions("stock2:TRADEDATA:list")
    @PostMapping("/selectTradeDataAndForetellListLessDate")
    @ResponseBody
    public TableDataInfo selectTRADEDATAListLessDate(TRADEDATA tRADEDATA)
    {
        //获取之前200天历史数据
        List<TradeDataAndForetell> list = tRADEDATAService.selectTradeDataAndForetellListLessDate(tRADEDATA);
        //获取以后10天历史数据
        List<TradeDataAndForetell> list_more_thisdate = tRADEDATAService.selectTradeDataAndForetellListMoreDate(tRADEDATA);
        for(int i = 0 ; i < list_more_thisdate.size() ; i++){
            list.add(0, list_more_thisdate.get(i));
        }
        return getDataTable(list);
    }


    /**
     * 导出交易数据列表
     */
    @RequiresPermissions("stock2:TRADEDATA:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRADEDATA tRADEDATA)
    {
        List<TRADEDATA> list = tRADEDATAService.selectTRADEDATAList(tRADEDATA);
        ExcelUtil<TRADEDATA> util = new ExcelUtil<TRADEDATA>(TRADEDATA.class);
        return util.exportExcel(list, "TRADEDATA");
    }

    /**
     * 新增交易数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交易数据
     */
    @RequiresPermissions("stock2:TRADEDATA:add")
    @Log(title = "交易数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRADEDATA tRADEDATA)
    {
        return toAjax(tRADEDATAService.insertTRADEDATA(tRADEDATA));
    }

    /**
     * 修改交易数据
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TRADEDATA tRADEDATA = tRADEDATAService.selectTRADEDATAById(id);
        mmap.put("tRADEDATA", tRADEDATA);
        return prefix + "/edit";
    }

    /**
     * 修改保存交易数据
     */
    @RequiresPermissions("stock2:TRADEDATA:edit")
    @Log(title = "交易数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRADEDATA tRADEDATA)
    {
        return toAjax(tRADEDATAService.updateTRADEDATA(tRADEDATA));
    }

    /**
     * 删除交易数据
     */
    @RequiresPermissions("stock2:TRADEDATA:remove")
    @Log(title = "交易数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tRADEDATAService.deleteTRADEDATAByIds(ids));
    }
}
